﻿//********************************************************************************//
//创建日期：<创建日期，2016-04-26>
//创建作者：<朱大鹏，zhudapeng@shanghai3h.com>
//功能说明：来函受理管理
//********************************************************************************//
using System;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Web.Class;

namespace Web.Pages.YongShui._13.LAIHANGL
{
    public partial class LAIHANSLGL : BasePage
    {
        #region 属性

        #endregion

        #region 变量
        /// <summary>
        /// 数据库访问
        /// </summary>
        SpHelper _sphelper = new SpHelper();
        /// <summary>
        /// 访问管理块信息
        /// </summary>
        YS_JX_GUANLIKBLL glkbll = new YS_JX_GUANLIKBLL();
        #endregion

        #region 事件
        /// <summary>
        /// 页面加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
                FouseChange();
            }
            LoadData();
        }
        /// <summary>
        /// 树形菜单改变选项时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void treeGuanLiK_FocusedNodeChanged(object sender, EventArgs e)
        {
            FouseChange();
        }
        /// <summary>
        /// 隐藏按钮事件   当文本框中按回车时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnSearch_Click(object sender, EventArgs e)
        {
            FouseChange();
        }
        /// <summary>
        /// 下拉框选项改变时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void DrpLX_SelectIndexChange(object sender, EventArgs e)
        {
            FouseChange();
        }
        /// <summary>
        /// 修改按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnEdit_Click(object sender, EventArgs e)
        {
            EditData();
        }
        #endregion

        #region 方法
        /// <summary>
        /// 获得当前选中行
        /// </summary>
        private void EditData()
        {
            int index = gvWenJianGZ.FocusedRowIndex;
            if (index > -1)
            {
                object tempColumnValues = this.gvWenJianGZ.GetRowValues(index, "S_LAIHANBH");
                PageTools.AlertMsg(this, tempColumnValues.ToString());
            }
            else
            {
                PageTools.AlertMsg(this, "请选择数据后继续操作");
            }

        }
        /// <summary>
        /// 条件改变时根据条件绑定数据
        /// </summary>
        private void FouseChange()
        {
            if (null != treeGuanLiK.FocusedNode)
            {
                var node = treeGuanLiK.FocusedNode;
                if (node.Level == 2)
                {
                    string GuanLiKuaiID = ((System.Data.DataRowView)(node.DataItem)).Row.ItemArray[1].ToString().Split('_')[0];
                    string year = ((System.Data.DataRowView)(node.DataItem)).Row.ItemArray[1].ToString().Split('_')[1];

                    BindGV(GuanLiKuaiID, year);
                }
                else
                {
                    if (node.ChildNodes.Count > 0)
                    {
                        var childNode = node.ChildNodes[0];
                        string GuanLiKuaiID = ((System.Data.DataRowView)(childNode.DataItem)).Row.ItemArray[1].ToString().Split('_')[0];
                        string year = ((System.Data.DataRowView)(childNode.DataItem)).Row.ItemArray[1].ToString().Split('_')[1];
                        BindGV(GuanLiKuaiID, year);

                    }
                    else
                    {
                        BindGV("0", "0");
                    }
                }
            }
        }
        /// <summary>
        /// 绑定gv数据
        /// </summary>
        /// <param name="glk"></param>
        /// <param name="year"></param>
        private void BindGV(string glk, string year)
        {
            DataTable dtZhandian = BusinessTool.GetTextAndValue("view_as_userinfo", "ZHANDIANMC", "ZHANDIANBH", null, string.Format("account='{0}'", LoginInfo.CurrentUser.Account)).Tables[0];
            string zhandianBH = "";
            if (dtZhandian != null && dtZhandian.Rows.Count > 0)
            {
                zhandianBH = dtZhandian.Rows[0]["VALUE"].ToString();
            }
            DataSet ds = _sphelper.P_YS_LH_LAIHANXXSLCX(glk, year, txtLHBH.Text.Trim(), txtYHH.Text.Trim(), txtXKH.Text.Trim(), Convert.ToInt32(DrpLX.Value), zhandianBH);
            gvWenJianGZ.DataSource = ds;
            gvWenJianGZ.DataBind();
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                //lanhanbh.Value = ds.Tables[0].Rows[0]["ID"].ToString();
                gvWenJianGZ.FocusedRowIndex = -1;
                gvWenJianGZ.FocusedRowIndex = 0;
            }
        }
        /// <summary>
        /// 初始化页面绑定数据
        /// </summary>
        private void InitControl()
        {


            DataSet ds = _sphelper.P_YS_LH_LAIHANLX(BusinessTool.WType);

            DrpLX.DataSource = ds;
            DrpLX.TextField = "S_LAIHANLXMC";
            DrpLX.ValueField = "I_LAIHANH";
            DrpLX.DataBind();

            DrpLX.SelectedIndex = 0;


        }
        /// <summary>
        /// 绑定树形
        /// </summary>
        private void LoadData()
        {
            DataTable dtZhandian = BusinessTool.GetTextAndValue("view_as_userinfo", "ZHANDIANMC", "ZHANDIANBH", null, string.Format("account='{0}'", LoginInfo.CurrentUser.Account)).Tables[0];
            string zhandianBH = "";
            if (dtZhandian != null && dtZhandian.Rows.Count > 0)
            {
                zhandianBH = dtZhandian.Rows[0]["VALUE"].ToString();
            }
            if (zhandianBH == "")
            {
                return;
            }

            DataSet glkdt = _sphelper.P_YS_LH_GUANLIKYM(zhandianBH,1);
            if (null != glkdt && glkdt.Tables.Count > 0)
            {
                var table = glkdt.Tables[0];
                treeGuanLiK.KeyFieldName = "S_GUANLIKH";
                treeGuanLiK.ParentFieldName = "ParentId";
                treeGuanLiK.DataSource = table;
                treeGuanLiK.DataBind();
            }
        }
        #endregion
    }
}